//对axios二次封装
import axios from 'axios';
import nprogress from 'nprogress';
import "nprogress/nprogress.css";
import store from '@/store';

const request = axios.create({
  baseURL:'/api',
  timeout:5000,
})

/**
 * 请求拦截器
 */
request.interceptors.request.use((config)=>{
  // 进度条开始
  nprogress.start();

  if (store.state.detail.uuid_token){
    config.headers.userTempId = store.state.detail.uuid_token;
  }
  if(store.state.user.token){
    config.headers.token = store.state.user.token;
 }
 
  return config
})

/**
 * 响应拦截器
 */
request.interceptors.response.use((res)=>{
  // 进度条结束
  nprogress.done();
  return res.data
},(error) => {
  return Promise.reject(new Error(error))
})


export default request
